package com.imay.live.adapter;

import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.imay.base.util.StringUtil;
import com.imay.live.helper.HotLabelCallBack;
import com.imay.live.helper.LabelViewMode;
import com.imay.live.helper.SuggestViewModel;
import com.imay.live.model.AssortmentModel;
import com.imay.live.R;

import java.util.List;

/**
 * Created by liangzhenxiong on 2017/4/6 0006.
 * 发现-分类
 */

public class AssortmentLinearAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {

    HotLabelCallBack hotLabelCallBack;
    public final static int VIEWTYPE_LINEAR_AREA = 1;//栏目
    public final static int VIEWTYPE_LINEAR_SUGGEST = 2;//推荐标签
    public final static int VIEWTYPE_LINEAR_HOT = 3;//热门
    public final static int VIEWTYPE_LINEAR_HOTTAG = 4;//热门标签

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public AssortmentLinearAdapter(List<MultiItemEntity> data, HotLabelCallBack hotLabelCallBack) {
        super(data);
        this.hotLabelCallBack = hotLabelCallBack;
        addItemType(VIEWTYPE_LINEAR_AREA, R.layout.item_assortment_area);
        addItemType(VIEWTYPE_LINEAR_SUGGEST, R.layout.item_assortment_areaall);
        addItemType(VIEWTYPE_LINEAR_HOT, R.layout.item_assortment_hot);
        addItemType(VIEWTYPE_LINEAR_HOTTAG, R.layout.item_assortment_tab);
    }


    @Override
    protected void convert(final BaseViewHolder helper, MultiItemEntity item) {
        if (item.getItemType() == VIEWTYPE_LINEAR_SUGGEST) {
            if (item instanceof SuggestViewModel) {
                final SuggestViewModel suggestViewModel = (SuggestViewModel) item;
                TextView tv_cityfirt = helper.getView(R.id.tv_cityfirt);
                if (tv_cityfirt != null) {
                    if (suggestViewModel.getLabel().size() > 2) {
                        tv_cityfirt.setText(suggestViewModel.getLabel().get(1));
                        tv_cityfirt.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if (hotLabelCallBack != null) {
                                    hotLabelCallBack.onClickTitle(suggestViewModel.getLabel().get(1));
                                }
                            }
                        });
                    }
                }
                TextView tv_citysecond = helper.getView(R.id.tv_citysecond);
                if (tv_citysecond != null) {
                    if (suggestViewModel.getLabel().size() > 3) {
                        tv_citysecond.setText(suggestViewModel.getLabel().get(2));
                        tv_citysecond.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if (hotLabelCallBack != null) {
                                    hotLabelCallBack.onClickTitle(suggestViewModel.getLabel().get(2));
                                }
                            }
                        });
                    }

                }
                TextView tv_citythree = helper.getView(R.id.tv_citythree);
                if (tv_citythree != null) {
                    if (suggestViewModel.getLabel().size() > 4) {
                        tv_citythree.setText(suggestViewModel.getLabel().get(3));
                        tv_citythree.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if (hotLabelCallBack != null) {
                                    hotLabelCallBack.onClickTitle(suggestViewModel.getLabel().get(3));
                                }
                            }
                        });
                    }
                }
            }

        } else if (item.getItemType() == VIEWTYPE_LINEAR_HOTTAG) {
            if (item instanceof LabelViewMode) {
                final LabelViewMode labelViewMode = (LabelViewMode) item;
                TextView textView = helper.getView(R.id.tv_titlehot);
                TextView tv_tabhot = helper.getView(R.id.tv_tabhot);
                if (textView != null) {
                    textView.setText(helper.getConvertView().getResources().getString(R.string.str_imay_type) + labelViewMode.getLabel());
                    helper.convertView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (hotLabelCallBack != null) {
                                hotLabelCallBack.onClickTitle(helper.getConvertView().getResources().getString(R.string.str_imay_type) + labelViewMode.getLabel());
                            }
                        }
                    });

                }
                if (StringUtil.isEmpty(labelViewMode.getStatus())) {
                    tv_tabhot.setVisibility(View.GONE);
                } else {
                    tv_tabhot.setText(labelViewMode.getStatus());
                    tv_tabhot.setVisibility(View.VISIBLE);
                }
            }
        } else if (item.getItemType() == VIEWTYPE_LINEAR_AREA) {
            if (item instanceof AssortmentModel) {
                final AssortmentModel assortmentModel = (AssortmentModel) item;
                helper.convertView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (hotLabelCallBack != null) {
                            hotLabelCallBack.onClickSuggest(assortmentModel.getLabels());
                        }
                    }
                });
            }

        }
    }
}
